﻿// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (c) 2007 Microsoft Corporation. All rights reserved.

using Microsoft.Office.Tools;

namespace TShooter.TfsWord.AddIn.UIManager
{
    /// <summary>
    /// Base class for all UIManagers in Outlook, Word and InfoPath applications.
    /// </summary>
    /// <typeparam name="TContainer">Type of the UIContainer.</typeparam>
    /// <typeparam name="TWindow">Type of the Window.</typeparam>
    public abstract class UIManagerBase<TContainer, TWindow>
        where TContainer : UIContainerBase<TWindow> 
        where TWindow : class
    {
        #region Fields

        private readonly UIContainerCollection<TContainer, TWindow> containers; // UI container collection
        private readonly CustomTaskPaneCollection customTaskPanes; // shared custom task pane collection

        #endregion

        #region .ctor

        protected UIManagerBase(CustomTaskPaneCollection customTaskPanes)
        {
            containers = new UIContainerCollection<TContainer, TWindow>(this);
            this.customTaskPanes = customTaskPanes;
        }

        #endregion

        #region Properties

        /// <summary>
        /// Gets the UIContainer collection.
        /// </summary>
        public UIContainerCollection<TContainer, TWindow> UIContainers
        {
            get { return containers; }
        }

        /// <summary>
        /// Gets the custom task pane collection.
        /// </summary>
        public CustomTaskPaneCollection CustomTaskPanes
        {
            get { return customTaskPanes; }
        }

        /// <summary>
        /// Gets container for the provided window. 
        /// If container is not found then a new container created.
        /// </summary>
        /// <param name="window"></param>
        /// <returns></returns>
        public TContainer this[TWindow window]
        {
            get { return containers.GetContainer(window); }
        }

        #endregion

        #region Abstract methods

        /// <summary>
        /// Requires inherited UIManager to override a method to instantiate a UIContainer object.
        /// </summary>
        /// <param name="window">Target window which will be hosted in the UIContainer.</param>
        /// <returns>The newly created UIContainer object.</returns>
        internal abstract TContainer CreateContainer(TWindow window);

        #endregion
    }
}